package com.dhsc.service.impl.khyjgl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.khzl.common.DictVo;
import com.dhsc.domain.ywzx.khyjgl.YjshbsqVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.khyjgl.IYjspbsqDao;
import com.dhsc.service.khyjgl.IYjsqbsqService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class YjsqbsqServiceImpl implements IYjsqbsqService {

    @Autowired
    private IYjspbsqDao yjspbsqDao;

    @Override
    public LayuiTableVo queryYjsqbshxx(YjshbsqVo y) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(y.getPage(), y.getLimit());
            List<YjshbsqVo> list = yjspbsqDao.queryYjsqbshxx(y);
            PageInfo<YjshbsqVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询佣金审批表申请信息出错",e);
            throw new MyException("查询佣金审批表申请信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryYjsqClzt(DictVo d) {
        ResponseObject obj = new ResponseObject();
        try {
            List<DictVo> list = yjspbsqDao.queryYjsqClzt(d);
            obj.setData(list);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("查询佣金审批表申请处理状态出错",e);
            throw new MyException("查询佣金审批表申请处理状态出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryYjsqLx(DictVo d) {
        ResponseObject obj = new ResponseObject();
        try {
            List<DictVo> list = yjspbsqDao.queryYjsqLx(d);
            obj.setData(list);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("查询佣金审批表申请类型字典出错",e);
            throw new MyException("查询佣金审批表申请类型字典出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryYjsqSfxc(DictVo d) {
        ResponseObject obj = new ResponseObject();
        try {
            List<DictVo> list = yjspbsqDao.queryYjsqSfxc(d);
            obj.setData(list);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("查询佣金审批表申请是否现场字典出错",e);
            throw new MyException("查询佣金审批表申请是否现场字典出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject uploadKhyjFile(YjshbsqVo y) {
        ResponseObject obj = new ResponseObject();
        try {
            //保存文件信息
            yjspbsqDao.insertKhyjWjxx(y);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("保存佣金申请上传文件信息错误",e);
            throw new MyException("保存佣金申请上传文件信息错误",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryYjspsqByid(YjshbsqVo y) {
        ResponseObject obj = new ResponseObject();
        try {
            //保存佣金审核信息
            YjshbsqVo yjshbsqVo =  yjspbsqDao.queryYjspsqByid();
            obj.setData(yjshbsqVo);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("查询表cgzx.yjshsq下一个bh错误",e);
            throw new MyException("查询表cgzx.yjshsq下一个bh错误",e);
        }
        return obj;
    }

    @Override
    public ResponseObject saveYjspsqxx(YjshbsqVo y) {
        ResponseObject obj = new ResponseObject();
        try {
            //保存佣金审核信息
            yjspbsqDao.insertKhyjxx(y);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("保存佣金审批申请信息错误",e);
            throw new MyException("保存佣金审批申请信息错误",e);
        }
        return obj;
    }

    @Override
    public LayuiTableVo queryYjsqbsh(YjshbsqVo y) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(y.getPage(), y.getLimit());
            List<YjshbsqVo> list = yjspbsqDao.queryYjsqbsh(y);
            PageInfo<YjshbsqVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询佣金审批表审核信息出错",e);
            throw new MyException("查询佣金审批表审核信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject deleteYjspsqxx(YjshbsqVo y) {
        ResponseObject obj = new ResponseObject();
        try {
            yjspbsqDao.deleteYjspsqxx(y);
            obj.setStatus(200);
        }catch (Exception e){
            log.error("删除佣金审批申请信息错误",e);
            throw new MyException("删除佣金审批申请信息错误",e);
        }
        return obj;
    }
}
